package com.alex.common.tools;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class StringUtils {
	// no html yet
	public static String getLimitedCharString(String str, int limitedChar) {
		if (str == null || "".equals(str)) {
			return str;
		}

		String regEx_html = "<[^>]+>"; // 定义HTML标签的正则表达式
		Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
		Matcher m_html = p_html.matcher(str);
		str = m_html.replaceAll("").trim(); // 过滤html标签

		char[] cStrc = str.toCharArray();
		if (cStrc.length <= limitedChar) {
			return str;
		} else {
			return new String(Arrays.copyOfRange(cStrc, 0, limitedChar));
		}

	}
}
